package com.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dk.mapper.SubscribeMapper;
import com.dk.mapper.SubscribeOkMapper;
import com.dk.pojo.Tbsubscribe;
import com.dk.pojo.Tbsubscribepass;
import com.dk.service.SubscribeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class subscribeServiceimpl implements SubscribeService {
    @Autowired
    private SubscribeMapper subscribeMapper;
    @Autowired
    private SubscribeOkMapper subscribeOkMapper;
    @Override
    public void subacribe(Tbsubscribe sub) {
        subscribeMapper.insert(sub);
    }

    @Override
    public List<Tbsubscribe> getnopass() {
        QueryWrapper<Tbsubscribe> wrapper = new QueryWrapper<>();
        wrapper.ne("status","1");
        List<Tbsubscribe> list = subscribeMapper.selectList(wrapper);
        return list;
    }

    @Override
    public void pass(Long id) {
        Tbsubscribe tbsubscribe = new Tbsubscribe();
        tbsubscribe.setId(id);
        tbsubscribe.setStatus("1");
        subscribeMapper.updateById(tbsubscribe);
    }

    @Override
    public void nopass(Long id) {
        Tbsubscribe tbsubscribe = new Tbsubscribe();
        tbsubscribe.setId(id);
        tbsubscribe.setStatus("2");
        subscribeMapper.updateById(tbsubscribe);
    }

    @Override
    public void subscribeOK() {
        QueryWrapper<Tbsubscribe> wrapper = new QueryWrapper<>();
        wrapper.eq("status","1");
        List<Tbsubscribe> list = subscribeMapper.selectList(wrapper);
        Tbsubscribepass tbsubscribepass = new Tbsubscribepass();
        for (Tbsubscribe tbsubscribe : list) {

            tbsubscribepass.setName(tbsubscribe.getName());
            tbsubscribepass.setPhone(tbsubscribe.getPhone());
            tbsubscribepass.setTime(tbsubscribe.getTime());
            tbsubscribepass.setAddress(tbsubscribe.getAddress());
            tbsubscribepass.setStatus(tbsubscribe.getStatus());
        }
        subscribeOkMapper.insert(tbsubscribepass);

    }
}
